<template>
  <div class="app-container">
    <!-- 列表 -->
    <el-table
      v-loading="listLoading"
      :data="list"
      stripe
      border
      @selection-change="handleSelectionChange"
      style="width: 100%;margin-top: 10px;"
    >
      <el-table-column type="selection" width="40"></el-table-column>
      <el-table-column
        label="序号"
        width="70"
        align="center"
      >
        <template slot-scope="scope">
          {{ (page - 1) * limit + scope.$index + 1 }}
        </template>
      </el-table-column>

      <el-table-column prop="orderId" label="订单ID" align="center"/>
      <el-table-column prop="msPrice" label="秒杀价格" align="center"/>
      <el-table-column prop="goodsPrice" label="商品价格" align="center"/>
      <el-table-column prop="goodsTitle" label="商品标题" align="center"/>
      <el-table-column prop="goodsDetail" label="商品详情" align="center"/>
      <el-table-column prop="createDate" label="创建时间" align="center"/>

      <el-table-column label="操作" align="center" fixed="right">
        <template slot-scope="scope">
          <el-button
            type="text"
            icon="el-icon-view"
            @click="view(scope.row)"
          >商品详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页组件 -->
    <el-pagination
      :current-page="page"
      :total="total"
      :page-size="limit"
      style="padding: 30px 0; text-align: center;"
      layout="total, prev, pager, next, jumper"
      @current-change="fetchData"
    />

  </div>
</template>
<script>
import { getOrderInfo } from '@/api/seck/seckill'

export default {
  data() {
    return {
      listLoading: false, // 数据是否正在加载
      list: null, // 列表
      total: 0, // 数据库中的总记录数
      page: 1, // 默认页码
      limit: 10, // 每页记录数
      searchObj: {} // 查询表单对象
    }
  },
  created() {
    // 调用列表方法
    this.fetchData()
  },
  methods: {
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.orderId)
      // this.tableNames = selection.map(item => item.ruleName)
      // this.single = selection.length !== 1
      // this.multiple = !selection.length
    },
    fetchData(page = 1) {
      this.page = page
      getOrderInfo(this.page, this.limit)
        .then(response => {
          this.list = response.data.records
          this.total = response.data.total
        })
    },
    view(row) {
      this.$router.push('/seckill/goodDetails?show=1&id=' + row.goodsId)
    }
  }
}
</script>
